package com.sunlee.common.core.aspect;

import com.sunlee.common.core.enums.ErrorCodeEnum;
import com.sunlee.common.core.exception.SysException;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * Redis切面处理类
 *
 * @author sunlee
 */
@Aspect
@Component
public class RedisAspect {

    /**
     * 是否开启redis缓存  true开启   false关闭
     */
    @Value("${xjppt.redis.open}")
    private boolean open;

    @Around("execution(* com.sunlee.common.core.redis.RedisUtils.*(..))")
    public Object around(ProceedingJoinPoint point) throws Throwable {

        if (!open) {
            return null;
        }

        try {
            return point.proceed();
        } catch (Exception e) {
            throw new SysException(ErrorCodeEnum.INTERFACE_INNER_INVOKE_ERROR.format("redis"), e);
        }
    }
}
